package util.android.form.respuesta;

import util.StringUtil;
import util.form.pregunta.Friend;
import util.form.pregunta.Restriccion1;
import android.widget.NumberPicker;

public class NumberPickerInput 
extends AbstractInputAndroid1<NumberPicker,NumberPickerInput>
{
	//Android Adventures - Pickers
	//http://www.i-programmer.info/programming/android/6418-android-adventures-pickers.html?start=2
	
	public NumberPickerInput(NumberPicker numberPicker) {
		super(numberPicker);
		setSoloLectura(false);
	}

	@Override
	public String getValor() {
		return view.getValue()+"";
	}

	@Override
	public void soloSetValor(String valor) {
		if(valor!=null && !valor.isEmpty())
			view.setValue(Integer.parseInt(valor));
	}

		
	public void soloLectura(boolean soloLectura) {
		
		
	}

	
	public NumberPickerInput setPositivo() {
		Friend.numberPickerInput(this,new Restriccion1() {			
			@Override
			public String validar(String valor) throws Exception {
				int v = StringUtil.StringtoInt(valor);
				if(!(v>0))
					return "Valor debe ser mayor a cero";						
				return null;
			}
		});
		return this;
	}
	
	public NumberPickerInput setRangoValores(int valorMinimo, int valorMaximo) {
		view.setMinValue(valorMinimo);
		view.setMaxValue(valorMaximo);		
		return this;
	}
}
